/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.awpspace.caromini;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;

/**
 * @author phamk_000
 */
public class MenuGame extends GameCanvas implements CommandListener {

	/**
	 * constructor
	 */
	private Image imBg, imPanel, imMenIn, imOneUp, imOneDown, imTwoUp,
			imTwoDown, imHelpUp, imHelpDown, imInforUp, imInforDown;
	private Button oneplayer, twoplayer, help, infor;
	private MySprite menu;
	private CaroMini mid;
	private boolean isMenu = false;

<<<<<<< .mine
	Command back;
	
	public MenuGame(CaroMini mid) {
		super(true);
		setFullScreenMode(true);
		this.mid = mid;
		try {
			back = new Command("back", Command.BACK, 0);
			addCommand(back);
			setCommandListener(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
		load();
		loadButton();
		setListener();
	}
=======
	public MenuGame(CaroMini mid) {
		super(true);
		setFullScreenMode(true);
		this.mid = mid;
		try {
>>>>>>> .r11

<<<<<<< .mine
	private void load() {
		imBg = loadImage("/bgmenu.png");
		imPanel = loadImage("/panel.png");
		imMenIn = loadImage("/menu.png");
		imOneUp = loadImage("/oneplayerup.png");
		imOneDown = loadImage("/oneplayerdown.png");
		imTwoUp = loadImage("/twoplayerup.png");
		imTwoDown = loadImage("/twoplayerdown.png");
		imHelpUp = loadImage("/helpup.png");
		imHelpDown = loadImage("/helpdown.png");
		imInforUp = loadImage("/inforup.png");
		imInforDown = loadImage("/infordown.png");
=======
			setCommandListener(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
		load();
		loadButton();
		setListener();
	}
>>>>>>> .r11

<<<<<<< .mine
	}
=======
	private void load() {
		imBg = loadImage("/bgmenu.png");
		imPanel = loadImage("/panel.png");
		imMenIn = loadImage("/menu.png");
		imOneUp = loadImage("/oneplayerup.png");
		imOneDown = loadImage("/oneplayerdown.png");
		imTwoUp = loadImage("/twoplayerup.png");
		imTwoDown = loadImage("/twoplayerdown.png");
		imHelpUp = loadImage("/helpup.png");
		imHelpDown = loadImage("/helpdown.png");
		imInforUp = loadImage("/inforup.png");
		imInforDown = loadImage("/infordown.png");
>>>>>>> .r11

<<<<<<< .mine
	private void loadButton() {
		menu = new MySprite(imMenIn, 2, 1, 197, 280);
		oneplayer = new Button(imOneUp, imOneDown, 8, 280);
		twoplayer = new Button(imTwoUp, imTwoDown, 52, 280);
		help = new Button(imHelpUp, imHelpDown, 117, 280);
		infor = new Button(imInforUp, imInforDown, 159, 280);
	}
=======
	}
>>>>>>> .r11

<<<<<<< .mine
	private void setListener() {
		oneplayer.setListener(new ButtonListener() {
			public void actionUp() {
				super.actionUp();
				mid.getDisplay().setCurrent(new OneGameScreen(mid));
=======
	private void loadButton() {
		menu = new MySprite(imMenIn, 2, 1, 197, 280);
		oneplayer = new Button(imOneUp, imOneDown, 8, 280);
		twoplayer = new Button(imTwoUp, imTwoDown, 52, 280);
		help = new Button(imHelpUp, imHelpDown, 117, 280);
		infor = new Button(imInforUp, imInforDown, 159, 280);
	}
>>>>>>> .r11

<<<<<<< .mine
			}
		});
		twoplayer.setListener(new ButtonListener() {
			public void actionUp() {
				// TODO Auto-generated method stub
				super.actionUp();
				mid.getDisplay().setCurrent(new TwoGameScreen(mid));
=======
	private void setListener() {
		oneplayer.setListener(new ButtonListener() {
			public void actionUp() {
				super.actionUp();
				mid.getDisplay().setCurrent(new OneGameScreen(mid));
>>>>>>> .r11

<<<<<<< .mine
			}
		});
		help.setListener(new ButtonListener() {
			public void actionUp() {
				// TODO Auto-generated method stub
				super.actionUp();
				Alert alert = new Alert(
						"How to play",
						"Caro Easy is easy mode of Caro Game. You can play with mobile or your friends."
								+ "\nHaving Fun.", null, AlertType.INFO);
				alert.addCommand(new Command("OK", Command.OK, 0));
				mid.getDisplay().setCurrent(alert, MenuGame.this);
=======
			}
		});
		twoplayer.setListener(new ButtonListener() {
			public void actionUp() {
				// TODO Auto-generated method stub
				super.actionUp();
>>>>>>> .r11

<<<<<<< .mine
			}
		});
		infor.setListener(new ButtonListener() {
			public void actionUp() {
				// TODO Auto-generated method stub
				super.actionUp();
				showAbout();
			}
		});
	}
=======
			}
		});
		help.setListener(new ButtonListener() {
			public void actionUp() {
				// TODO Auto-generated method stub
				super.actionUp();
				Alert alert = new Alert(
						"How to play",
						"Caro Easy is easy mode of Caro Game. You can play with mobile or your friends."
								+ "\nHaving Fun.", null, AlertType.INFO);
				alert.addCommand(new Command("OK", Command.OK, 0));
				mid.getDisplay().setCurrent(alert, MenuGame.this);
>>>>>>> .r11

<<<<<<< .mine
	private Image loadImage(String path) {
		return ImageLoader.getInstance().loadImage(path);
	}
=======
			}
		});
		infor.setListener(new ButtonListener() {
			public void actionUp() {
				// TODO Auto-generated method stub
				super.actionUp();
				showAbout();
			}
		});
	}
>>>>>>> .r11

<<<<<<< .mine
	public void paint(Graphics g) {
		g.drawImage(imBg, 0, 0, Graphics.TOP | Graphics.LEFT);
		if (isMenu) {
			g.drawImage(imPanel, 0, 277, 0);
			oneplayer.draw(g);
			twoplayer.draw(g);
			help.draw(g);
			infor.draw(g);
		}
		menu.paint(g);
	}
=======
	private Image loadImage(String path) {
		return ImageLoader.getInstance().loadImage(path);
	}
>>>>>>> .r11

<<<<<<< .mine
	/**
	 * Called when the pointer is pressed.
	 */
	protected void pointerPressed(int x, int y) {
		if (inSprite(menu, x, y)) {
			menu.nextFrame();
			isMenu = !isMenu;
			repaint();
			return;
		}
		if (isMenu) {
			oneplayer.actionDown(x, y);
			twoplayer.actionDown(x, y);
			help.actionDown(x, y);
			infor.actionDown(x, y);
		}
		repaint();
	}
=======
	public void paint(Graphics g) {
		g.drawImage(imBg, 0, 0, Graphics.TOP | Graphics.LEFT);
		if (isMenu) {
			g.drawImage(imPanel, 0, 277, 0);
			oneplayer.draw(g);
			twoplayer.draw(g);
			help.draw(g);
			infor.draw(g);
		}
		menu.paint(g);
	}
>>>>>>> .r11

<<<<<<< .mine
	/**
	 * Called when the pointer is released.
	 */
	protected void pointerReleased(int x, int y) {
		if (isMenu) {
			oneplayer.actionUp(x, y);
			twoplayer.actionUp(x, y);
			help.actionUp(x, y);
			infor.actionUp(x, y);
		}
		repaint();
	}
=======
	/**
	 * Called when the pointer is pressed.
	 */
	protected void pointerPressed(int x, int y) {
		if (inSprite(menu, x, y)) {
			menu.nextFrame();
			isMenu = !isMenu;
			repaint();
			return;
		}
		if (isMenu) {
			oneplayer.actionDown(x, y);
			twoplayer.actionDown(x, y);
			help.actionDown(x, y);
			infor.actionDown(x, y);
		}
		repaint();
	}
>>>>>>> .r11

<<<<<<< .mine
	public void showAbout() {
		Alert dialog = new Alert("About", "Development by withlovei."
				+ "\nhttps://www.facebook.com/AwpSpace?ref=hl"
				+ "\nEmail:phamkyit@gmail.com"
				+ "\n@Copyright of Awpspace team", null, AlertType.INFO);
		dialog.addCommand(new Command("OK", Command.OK, 1));
		mid.switchDisplayable(dialog, this);
	}
=======
	/**
	 * Called when the pointer is released.
	 */
	protected void pointerReleased(int x, int y) {
		if (isMenu) {
			oneplayer.actionUp(x, y);
			twoplayer.actionUp(x, y);
			help.actionUp(x, y);
			infor.actionUp(x, y);
		}
		repaint();
	}
>>>>>>> .r11

<<<<<<< .mine
	/**
	 * Called when action should be handled
	 */
	public void commandAction(Command command, Displayable displayable) {
		mid.exitMIDlet();
	}

	public boolean inSprite(Sprite s, int x, int y) {
		return x > s.getX() && x < s.getX() + s.getWidth() && y > s.getY()
				&& y < s.getY() + s.getHeight();
	}
=======
	public void showAbout() {
		Alert dialog = new Alert("About", "Development by withlovei."
				+ "\nhttps://www.facebook.com/AwpSpace?ref=hl"
				+ "\nEmail:phamkyit@gmail.com"
				+ "\n@Copyright of Awpspace team", null, AlertType.INFO);
		dialog.addCommand(new Command("OK", Command.OK, 1));
		mid.switchDisplayable(dialog, this);
	}

	/**
	 * Called when action should be handled
	 */
	public void commandAction(Command command, Displayable displayable) {
	}

	public boolean inSprite(Sprite s, int x, int y) {
		return x > s.getX() && x < s.getX() + s.getWidth() && y > s.getY()
				&& y < s.getY() + s.getHeight();
	}
>>>>>>> .r11
}
